package com.shroo8.footballblog.bo.api;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.shroo8.footballblog.dto.api.ArticleDto;
import com.shroo8.footballbloglib.dao.footballblogwrite.CreateArticleDao;

@Service(value="createArticleBo")
public class CreateArticleBoImpl implements CreateArticleBo{

	private static final Logger logger = LoggerFactory.getLogger(CreateArticleBoImpl.class);
	
	@Resource(name="createArticleDao")
	private CreateArticleDao createArticleDao;
	
	public ArticleDto createArticle(ArticleDto articleDto) throws DataAccessException{
		String articleId = createArticleDao.execute(articleDto.getAuthorId(), articleDto.getArticleTitle(), articleDto.getArticleText());
		logger.info("New chat id is: " + articleId);

		ArticleDto createdArticleDto = new ArticleDto();
		createdArticleDto.setArticleId(articleId);
		createdArticleDto.setAuthorId(articleDto.getAuthorId());
		createdArticleDto.setArticleTitle(articleDto.getArticleTitle());
		createdArticleDto.setArticleText(articleDto.getArticleText());
		
		return createdArticleDto;
	}

	public CreateArticleDao getCreateArticleDao() {
		return createArticleDao;
	}

	public void setCreateArticleDao(CreateArticleDao createArticleDao) {
		this.createArticleDao = createArticleDao;
	}

	
}
